package cn.owen.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.owen.mapper.UserMapper;
import cn.owen.model.User;

/**
 * user service
 * @author Burning
 * @email wenbao163.good@163.com
 * @date 2016年8月6日下午2:30:04
 *
 */

@Service
@Transactional
public class UserService {

    @Autowired
    private UserMapper userMapper;
    
    public void insert(User user){
    	userMapper.insert(user);
    }
    
    public void update(User user){
    	userMapper.updateByPrimaryKey(user);
    }
    
    public void delete(Integer id){
    	userMapper.deleteByPrimaryKey(id);
    }
    
    public PageInfo<User> selectPageUser(String pageNum, String pageSize, User user) {
		PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
		return new PageInfo<User>(userMapper.selectList(user));
	}
    
    public List<User> selectList(User user){
    	return userMapper.selectList(user);
    }
    
    public User selectById(Integer id){
    	return userMapper.selectByPrimaryKey(id);
    }
    
    public User getUserInfo(String name, String password){
        User user=userMapper.findUserInfo(name,password);
        return user;
    }

	public List<String> selectContents() {
		return userMapper.selectContents();
	}

	public int countContent(Map str) {
		return userMapper.countContent(str);
	}

	/**修改用户密码
	 * @param user
	 */
	public void updateUserPass(User user) {
		userMapper.updateUserPass(user);
	}
	
	public User selectByName(String name){
		return userMapper.selectByName(name);
	}
}
